package org.kisekiproject.objectset {

	/**
	 * A set of objects that can be queried in various ways.
	 */
	public class ObjectSet {

		private var _array:Array;

		/**
		 * Create an object set.
		 */
		public function ObjectSet(source:Array) {
			_array=source;
		}

		/**
		 * Sums the objects in the set.
		 */
		public function sum():Number {
			var res:Number=0;

			for each (var o:Object in _array)
				res+=o;

			return res;
		}

		/**
		 * Counts the objects in the set.
		 */
		public function count():int {
			return _array.length;
		}

		/**
		 * Slices the set vertically.
		 */
		public function slice(property:String):ObjectSet {
			//trace("slicing...");
			var a:Array=new Array();

			for each (var o:Object in _array)
				a.push(o[property]);

			return new ObjectSet(a);
		}

		/**
		 * Selects the objects that fulfill a criteria.
		 */
		public function where(expression:String):ObjectSet {
			return new ObjectSet([]);
		}

		/**
		 * Get array.
		 */
		public function get array():Array {
			return _array;
		}
	}
}